package org.advanced.io;

import java.io.FileInputStream;
import java.io.FileOutputStream;

/**
 * @author John.zhang
 * @version Id: Reads, v 1.0 2020/12/14 13:41 ZhiYong Exp $
 */
public class Reads {

    public static void main(String[] args) {
        try (FileInputStream fileInputStream = new FileInputStream("C:/data/io/io.txt");
             FileOutputStream fileOutputStream = new FileOutputStream("C:/data/io/io01.txt")) {
            int i = 0;
            byte[] buffer = new byte[3];
            while ((i = fileInputStream.read(buffer)) != -1) {
                //每次输出0到读取位置的长度，否则会出现前一次读出的多出的字符
                System.out.println(new String(buffer, 0, 1));
            }
            //读取指定目录的字节，如果read方法没有输入，会阻塞
            int read = fileInputStream.read();
            System.out.println((char) read);
            read = fileInputStream.read();
            System.out.println((char) read);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
